﻿using Fast;
using Fast.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// swagger文档服务扩展类
    /// </summary>
    [SkipScan]
    public static class SwaggerServiceCollectionExtensions
    {
        /// <summary>
        /// 添加Swagger文档服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="swaggerGenConfigure"></param>
        /// <returns></returns>
        public static IServiceCollection AddSwaggerDocument(this IServiceCollection services, Action<SwaggerGenOptions> swaggerGenConfigure = null)
        {
            // 判断是否启用规范化文档
            if (App.Settings.HasEnableSwaggerDocument != true) return services;

            // 添加配置
            services.AddConfigureOptions<SwaggerDocumentSettingsOptions>();

            // 添加Swagger生成器服务
            services.AddSwaggerGen(options => SwaggerDocumentBuilder.BuildGen(options, swaggerGenConfigure));

            // 添加 MiniProfiler 服务
            if (App.Settings.HasInjectMiniProfiler.Value) services.AddMiniProfiler(options => options.RouteBasePath = "/profiler").AddEntityFramework();

            return services;
        }
    }
}
